package 第二讲数据结构;

import java.util.Scanner;

public class AcWing828 {
	public static int N=(int)1e5+10;
	public static int top=0;
	public static int[] stack=new int[N];
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		while(m-->0) {
			String op=sc.next();
			if("push".equals(op)) {
				int x=sc.nextInt();
				push(x);
			}else if("pop".equals(op)) {
				pop();
			}else if("empty".equals(op)) {
				System.out.println(isEmpty());
			}else {
				System.out.println(query());
			}
		}
		sc.close();
		
		
	}
	public static void push(int x) {
		stack[++top]=x;
	}
	public static void pop() {
		top--;
	}
	public static String isEmpty() {
		return top==0?"YES":"NO"; 
	}
	
	public static int query() {
		return stack[top];
	}

}
